package tiled.simple.gwt.client;

import tiled.simple.core.Map;

import com.google.gwt.canvas.dom.client.Context2d;
import com.google.gwt.canvas.dom.client.CssColor;

public class Game {
	
	private Map map;
	private MapRenderer mapRenderer=new MapRenderer();
	
	public Game(Map map) {
		this.map=map;
		this.map.loadImages(mapRenderer);
	}
	
	float angle=0.3f;
		
	public void render(Context2d context,int refreshRate) {
		mapRenderer.context=context;
		
		mapRenderer.x_delta=(width-map.width*map.tilewidth)/2;
		mapRenderer.y_delta=(height-map.height*map.tileheight)/2;
				
		//fill black
        CssColor black = CssColor.make("rgba(0,0,0,255)");
        context.setFillStyle(black);
        context.fillRect(0,0,width,height);
        context.fill();

        //rotate -angle
		context.translate(width/2, height/2);
		context.rotate(-angle);
		context.translate(-width/2, -height/2);

		//fill black again
        context.setFillStyle(black);
        context.fillRect(0,0,width,height);
        context.fill();

		map.render(mapRenderer);
		
		// rotate +angle
		context.translate(width/2, height/2);
		context.rotate(angle);
		context.translate(-width/2, -height/2);

		
		angle=angle+0.01f;
    }
	
	private int width=0;
	private int height=0;
	
	public void resize(int width, int height) {
		this.width=width;
		this.height=height;
	}

}
